import request from '@/utils/request'
import mockAjax from '@/utils/request-mock'

import type { loginModel } from './model/login'
import type {searchModel,searchParam} from './model/search'
import type {categoryList} from './model/categoryList'
import type {detailModel} from './model/detail'
import type {cartListModel} from './model/cartList'
import type {tradeModel,PayOrder} from './model/trade'

// 发送三级导航的请求
export const reqGetBaseCategoryListDate = () =>
  request.get<any,categoryList>('/product/getBaseCategoryList')

// 获取轮播图的数据
export const reqGetBannerListData = () => mockAjax.get<any,any>('/banner')

// 请求获取floors数据
export const reqGetFloorsData = () => mockAjax.get<any,any>('/floors')

// search页面
export const reqGetSearchData = (searchParams:searchParam) => {
  return request.post<any,searchModel>('/list', searchParams)
}

// 详情页面
export const reqGetDetailInfoData = (id:number) => request.get<any,detailModel>(`/item/${id}`)

// 添加选择的商品到服务器 && 购物车里面再修改数量
export const reqAddOrUpdateCart = (skuId:number, skuNum:number) => {
  return request.post<any, null>(`/cart/addToCart/${skuId}/${skuNum}`)
}

// 获取购物车的数据
export const reqShopCart = () => {
  return request.get<any,cartListModel>(`/cart/cartList`)
}

// 购物车选中状态
export const reqUpdateCart = (skuID:number, isChecked:number) =>
  request.get<any, null>(`/cart/checkCart/${skuID}/${isChecked}`)

// 购物车批量更新购物车的状态
export const reqChangeCheckedState = (isChecked:number, skuIdList) =>
  request.post<any,any>({
    url: `/cart/batchCheckCart/${isChecked}`,
    method: 'post',
    data: skuIdList,
  })

// 删除一条商品
export const reqDelOneShopInfo = (skuId:number) =>
  request.delete<any, null>(`/cart/deleteCart/${skuId}`)

// 批量删除 请求体参数
export const reqDelSelectedShopCartInfo = (skuIdList) => {
  return request.delete<any, null>(`/cart/batchDeleteCart`, { data: skuIdList })
}

// 验证码
export const reqGetVerifyCode = (phone:number) =>
  request.get<any,any>(`/user/passport/sendCode/${phone}`)

export interface user {
  phone: string
  password: string
  code: string
}
// 实现注册 请求体参数
export const reqRegister = (user: user) =>
  request.post<any, number>('/user/passport/register', user)
// 登录
export const reqLogin = (user:user) =>
  request.post<any, loginModel>('/user/passport/login', user)
// 登出
export const reqLoginOut = () => request.get<any,any>('/user/passport/logout')

// 16. 获取邮寄地址 但是没有数据 就不管这个了 知道这个流程就行
export const reqGetUserAddressList = () =>
  request.get<any,any>('/api/user/userAddress/auth/findUserAddressList')

// 获取订单支付信息
export const reqGetTradeInfo = () => request.get<any,tradeModel>('/order/auth/trade')

export interface param {
  consignee :string
  consigneeTel :string
  deliveryAddress :string
  paymentWay :string
  orderComment :string
  orderDetailList :string
}

// 提交订单
export const reqSubmitPay = (tradeNo:string, params:param) =>
  request.post<any, number>(
    `/order/auth/submitOrder?tradeNo=${tradeNo}`,
    params
  )

// 订单支付信息
export const reqPayInfo = (orderId: number) =>
  request.get<any, PayOrder>(`/payment/weixin/createNative/${orderId}`)

// 查询支付订单状态
export const reqGetPayOrderState = (orderId: number) =>
  request.get<any, null>(`/payment/weixin/queryPayStatus/${orderId}`)

// 接口 测试
// ;(async () => {
//   const result = await reqGetPayOrderState()
// })()
